package com.linux.huhx.stringTest;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by huhx on 2017-06-14.
 */
public class VariableParam {
    private static void variableParam1(Object... args) {
        for (Object v : args) {
            System.out.print(v.toString() + " ");
        }
        System.out.println(args.length);
    }

    @Test
    public void param_1() {
        // 如果是List<String>
        List<String> lists1 = new ArrayList<>();
        lists1.add("huhx");
        lists1.add("linux");
        variableParam1(lists1); // [huhx, linux] 1

        // 如果是List<Object>
        List<Object> lists2 = new ArrayList<>();
        lists2.add("huhx");
        lists2.add("linux");
        variableParam1(lists2); // [huhx, linux] 1

        // 如果是数组
        String[] arrays1 = new String[]{"huhx", "linux"}; // huhx linux 2
        variableParam1(arrays1);

        // 如果是数组
        Object[] arrays2 = new Object[]{"huhx", "linux"};
        variableParam1(arrays1); // huhx linux 2

        // 如果是参数
        variableParam1("huhx", "linux"); // huhx linux 2
    }
}
